<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%String path = request.getContextPath() ;%>
<%
	String regionShowLvl = request.getParameter("regionShowLvl");
	if(regionShowLvl==null){
		regionShowLvl="3";//未设置显示级别 默认设置为3级(即省.市.县/区)
	}
%>
 
			<input name="rgnProvCd" id="rgnProvCd" data-value=" " placeholder="--请选择--" ltype="combobox">
			<span id="rgnProvCdSpan" class="requiredSymbol" style="display: none">*</span>
			<input name="rgnCityCd" id="rgnCityCd" data-value=" " placeholder="--请选择--" ltype="combobox">
			<span id="rgnCityCdSpan" class="requiredSymbol" style="display: none">*</span>
			<input name="rgnCountyCd" id="rgnCountyCd" data-value=" " placeholder="--请选择--" ltype="combobox">
			<span id="rgnCountyCdSpan" class="requiredSymbol" style="display: none">*</span>
	
			<input type="hidden" id="regionShowLvl" value="<%=regionShowLvl %>"/> 
<script type="text/javascript">
var _regionShowLvl=$("#regionShowLvl").val();

//修改时数据初始值   
var _rgnProvCdUpdataValue = "",//省
    _rgnCityCdUpdataValue = "",//市
    _rgnCountyUpdataValue = "";//县/区
    
$(function(){
	$("#rgnProvCd").ligerComboBox({
		valueField: 'key',
		textField: 'value',
		width:150,
		onChangeValue:function(value){
			if(value){
				initRegionCitySelectData(value);
			}else{
				var citySelectObj = liger.get("rgnCityCd");
				citySelectObj.selectValue(" ");
			}
		}
	});
	$("#rgnCityCd").ligerComboBox({
		valueField: 'key',
		textField: 'value',
		width:150,
		onChangeValue:function(value){
			if(value){
				initCountySelectData(value);
			}else{
				var countySelectObj = liger.get("rgnCountyCd");
				countySelectObj.selectValue(" ");
			}
		}
	});
	$("#rgnCountyCd").ligerComboBox({
		valueField: 'key',
		textField: 'value',
		width:150
	});
	
	//判断regionShowLvl参数  1:省   2:省市   3:省市县
	if(_regionShowLvl==1){
		$("#rgnCityCd").parents(".l-text-wrapper").remove();
		$("#rgnCountyCd").parents(".l-text-wrapper").remove();
	}else if(_regionShowLvl==2){
		$("#rgnCountyCd").parents(".l-text-wrapper").remove();
	}
	
	initRegionProvSelectData();
	
});
	//初始化省级数据
	function initRegionProvSelectData(){
		$.ajax({
			type: 'post',
			dataType:'json',
			url: '<%=path%>/system/sysRegion/getProvinceRegion.do',
			success:function(msg){
				 if(msg.success == 1){
					 var provSelectObj = liger.get("rgnProvCd");
					 provSelectObj.setData(msg.data);
					 if(StringUtils.isNotEmpty(_rgnProvCdUpdataValue)){
						 provSelectObj.selectValue(_rgnProvCdUpdataValue);
					 }else{
						 //provSelectObj.selectValue(msg.data[0].key);
					 }
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}

	//初始化市级数据(value:省代码)
	function initRegionCitySelectData(value){
		if(!$("#rgnCityCd").length)return;
		var provSelectObj = liger.get("rgnProvCd");
		var _provCd = provSelectObj.findValueByText(value);
		if(!_provCd){
			return;
		}
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{rgnCd:_provCd},
			url: '<%=path%>/system/sysRegion/getRegionByRgnCd.do',
			success:function(msg){
				 if(msg.success == 1){
					 var citySelectObj = liger.get("rgnCityCd");
					 if(msg.data){
						 citySelectObj.setData(msg.data);
						 if(StringUtils.isNotEmpty(_rgnCityCdUpdataValue)){
							 citySelectObj.selectValue(_rgnCityCdUpdataValue);
						 }else{
							 //citySelectObj.selectValue(msg.data[0].key);
						 }
					 }else{
						 citySelectObj.clear();
						 citySelectObj.setData({});//置空下拉框数据
						 var countySelectObj = liger.get("rgnCountyCd");
						 if(countySelectObj){
							 countySelectObj.clear();
							 countySelectObj.setData({});//置空下拉框数据
						 }
					 }
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	
	//初始化县/区数据(value:市代码)
	function initCountySelectData(value){
		if(!$("#rgnCountyCd").length)return;
		var citySelectObj = liger.get("rgnCityCd");
		var _cityCd = citySelectObj.findValueByText(value);
		if(!_cityCd){
			return;
		}
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{rgnCd:_cityCd},
			url: '<%=path%>/system/sysRegion/getRegionByRgnCd.do',
			success:function(msg){
				 if(msg.success == 1){
					 var countySelectObj = liger.get("rgnCountyCd");
					 if(msg.data){
						 countySelectObj.setData(msg.data);
						 if(StringUtils.isNotEmpty(_rgnCountyUpdataValue)){
							 countySelectObj.selectValue(_rgnCountyUpdataValue);
						 }else{
							 //countySelectObj.selectValue(msg.data[0].key);
						 }
					 }else{
						 countySelectObj.clear();
						 countySelectObj.setData({});//置空下拉框数据
					 }
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	
	//页面调用者可根据以下方法设置修改时的数据初始值
	function setRgnProvCdUpdataValue(value){//省
		_rgnProvCdUpdataValue = value;
	}
	function setRgnCityCdUpdataValue(value){//市
		_rgnCityCdUpdataValue = value;
	}
	function setRgnCountyCdUpdataValue(value){//县/区
		_rgnCountyUpdataValue = value;
	}
	//修改时设置数据初始值之后需要调用的事件
	function setRegionSelectDataChange(){
		var provSelectObj = liger.get("rgnProvCd");
		provSelectObj.selectValue(_rgnProvCdUpdataValue);
	}

	//获取区域下拉框选中值
	function getRgnProvCd(){ //省
		var provSelectObj = liger.get("rgnProvCd");
		var _provCd = provSelectObj.getValue();
		return _provCd;
	}
	function getRgnCityCd(){ //市
		var citySelectObj = liger.get("rgnCityCd");
		var _cityCd = citySelectObj.getValue();
		return _cityCd;
	}
	function getRgnCountyCd(){ //县/区
		var countySelectObj = liger.get("rgnCountyCd");
		var _countyCd = citySelectObj.getValue();
		return _countyCd;
	}
	
	//禁用省
	function disabledRgnProvCd(){
		liger.get("rgnProvCd").setDisabled(true);
	}
	//禁用市
	function disabledRgnCityCd(){
		liger.get("rgnCityCd").setDisabled(true);
	}
	//禁用县
	function disabledRgnCountyCd(){
		liger.get("rgnCountyCd").setDisabled(true);
	}
	
	//清除选中状态
	function clearRegionSelectStatus(){
		var rgnProvCdObj = liger.get("rgnProvCd");
		rgnProvCdObj.selectValue(" ");
		var rgnCityCdObj = liger.get("rgnCityCd");
		rgnCityCdObj.selectValue(" ");
		var rgnCountyCdObj = liger.get("rgnCountyCd");
		rgnCountyCdObj.selectValue(" ");
	}
	
	//设置省必填校验(参数:from表单ID)
	function valitadeRgnProvCd(formNm){
		var formSet1=liger.get(formNm);
		formSet1.setFieldValidate("rgnProvCd", {
	        required: true,
	        select: true
	    });
		$("#rgnProvCdSpan").show();
	}
	//设置市必填校验(参数:from表单ID)
	function valitadeRgnCityCd(formNm){
		var formSet1=liger.get(formNm);
		formSet1.setFieldValidate("rgnCityCd", {
	        required: true,
	        select: true
	    });
		$("#rgnCityCdSpan").show();
	}
	//设置县必填校验(参数:from表单ID)
	function valitadeRgnCountyCd(formNm){
		var formSet1=liger.get(formNm);
		formSet1.setFieldValidate("rgnCountyCd", {
	        required: true,
	        select: true
	    });
		$("#rgnCountyCdSpan").show();
	}
	
	
</script>

